@echo off

setlocal

set version=Debug
set objname=IExampleEvts
set target="%~dp0%version%\%objname%.dll"
set tlbfile="%~dp0%version%\%objname%.tlb"

set PATH=C:\Windows\Microsoft.NET\Framework\v4.0.30319;%PATH%

if not exist %target% (
  echo %target% is not generated!
  goto end
)

if not exist %tlbfile% (
  echo %tlbfile% is not generated!
  goto end
)

set clsid={BE7F95C9-E6B8-45b9-A2A8-F3530818D008}
set regbase=HKLM\Software\Classes\CLSID\%clsid%

set alias=%objname%.object
set reg_alias_base=HKLM\Software\Classes\%alias%

set desc="%objname% COM component"

reg add %regbase% /f /ve /t REG_SZ /d %desc% > nul 2>&1
if %errorlevel% neq 0 (
  echo Run this batch file as administrator!
  goto end
)
reg add %regbase%\InprocServer32 /f /ve /t REG_SZ /d %target% > nul 2>&1
reg add %regbase%\InprocServer32 /f /v ThreadingModel /t REG_SZ /d both > nul 2>&1
reg add %regbase%\ProgID /f /ve /t REG_SZ /d %alias% > nul 2>&1

reg add %reg_alias_base% /f /ve /t REG_SZ /d %desc% > nul 2>&1
reg add %reg_alias_base%\CLSID /f /ve /t REG_SZ /d %clsid% > nul 2>&1

regtlibv12 %tlbfile% > nul 2>&1

if %errorlevel% equ 9009 (
  echo Please add regtlibv12 path to PATH environment
  goto end
)

echo DONE!

:end
endlocal
pause
